package cn.afterturn.easypoi.word;
import cn.afterturn.easypoi.word.entity.bookmark.ExportExecel.NormalParagraph;
import cn.afterturn.easypoi.word.entity.bookmark.ExportExecel.TablePara;
import cn.afterturn.easypoi.word.entity.bookmark.WordEntityVO;
import cn.afterturn.easypoi.word.parse.excel.ExcelToListUtil;
import cn.afterturn.easypoi.word.vo.WordPage;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.junit.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import static junit.framework.TestCase.assertTrue;

public class JeecgReadyTest {
    private static SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd");
    @Test
    public void testJsonOutput()throws Exception{
        String filePath=System.getProperty("user.dir");
        String relativefilePath=filePath+"\\src\\main\\java\\cn\\afterturn\\easypoi\\word\\files\\";
        String url=relativefilePath+"t清单文件Normal.docx";
        WordService wordService=new WordService();
        WordEntityVO wordEntityVO=wordService.getwordParseBookMarkWordEntity(url);
        ObjectMapper mapper = new ObjectMapper();
        String jsonString = mapper.writeValueAsString(wordEntityVO);
        //Jackson将对象转换为json字符串时，设置默认的时间格式
        DateFormat dateformat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        mapper.setDateFormat(dateformat);//设置时间格

        mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
        mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);


        /*JSONObject json=new JSONObject(true);
        //String jsonData = json.toJSONString(wordEntityVO,SerializerFeature.WriteMapNullValue);
        String jsonData = json.toJSONString(wordEntityVO,SerializerFeature.MapSortField);*/
        System.out.println(jsonString);
    }
    @Test
    public void testXMLImport(){

    }
    /*
     * 准备移植到Jeecg中的测试
     * */
    @Test
    public  void getJeecgInputStreamwordParseGetBookMark() throws Exception{
        String filePath=System.getProperty("user.dir");
        String relativefilePath=filePath+"\\src\\main\\java\\cn\\afterturn\\easypoi\\word\\files\\";
        String url=relativefilePath+"t清单文件Normal.docx";

        InputStream inputStream = new FileInputStream(new File(url));
        WordPage wordPage= new WordService().getwordParseBookMark(inputStream,url);
        assertTrue(wordPage.getTableParaList().size() ==13);
    }
    @Test
    public void setJeecgBookValuefromNetwork() throws Exception{
        System.out.println("print");
        //导入Excel
        String filePath=System.getProperty("user.dir");
        String relativefilePath=filePath+"\\src\\main\\java\\cn\\afterturn\\easypoi\\word\\files\\";
        String exportImportFilepath=relativefilePath+"sjkimportces2.xlsx";
        String SaveUrl=relativefilePath+"exportimage";
        List<NormalParagraph> resultNormal=ExcelToListUtil.readExcelToList(exportImportFilepath,SaveUrl);
        //assertTrue(resultNormal.size() ==12);
        resultNormal.forEach(the -> {
            System.out.println(the.toString());
        });
        System.out.println("-----********************************--------------------------");
        List<TablePara> resulttable=ExcelToListUtil.readExcelToListTablePara(exportImportFilepath,SaveUrl);
        Assert.assertTrue(resulttable.size() ==19);
        resulttable.forEach(t -> {
            System.out.println(t.toString());
        });
        WordPage wordPage=new WordPage();
        wordPage.setTableParaList(resulttable);
        wordPage.setNormalParagraphList(resultNormal);
        Map<String,Object> map= new WordService().setMapFromWordPage(wordPage);
        assertTrue(map.size()>10);
    }
}
